#coding=utf-8
from uliweb import expose,json, functions

#可以省略直接引用
from uliweb import request, error

import datetime
import os


def __begin__():
    """
    用户验证 权限验证
    """
    from uliweb import functions
    functions.require_login()
    return functions.has_role()

@expose('/notify')
class Notify(object):

    def __init__(self):
        from uliweb.orm import get_model
        self.usermodel = get_model('user')
        self.notifymodel = get_model('notify')

    def notify(self):
        return {}
    
    def notifydel(self):
        """
        删除,支持批量和单一删除
        """
        if request.method == 'GET' or not request.user.is_superuser:
            error("你访问的页面不存在！请联系管理员")


        _id = request.POST.get('id')

        mid = []
        for i in _id.split(','):
            mid.append(int(i))       


        try:
            self.notifymodel.filter(self.notifymodel.c.id.in_(mid)).remove()

            d = {"status":200,"msg":"删除成功"}
        except:
            d = {"status":500,"msg":"删除失败"}

        return json(d)